package cn.truistic.enmicromsg.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import cn.truistic.enmicromsg.main.ui.MainActivity;

/**
 * 类名：BootBroadcastReceiver
 * 功能描述：启动时系统发出的广播的接收器
 * #<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 * @author android_ls
 */
public class BootBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = "BootBroadcastReceiver";

    private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i("TAG", "BootBroadcastReceiver onReceive(), Do thing!");

        //接收广播：系统启动完成后运行程序
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
        {
            Log.e(TAG, "BootBroadcastReceiver onReceive(), Do thing!");
            Intent ootStartIntent = new Intent(context, MainActivity.class);
            ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(ootStartIntent);
        }
        //接收广播：安装更新后，自动启动自己。
//        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED))
//        {
//            Intent ootStartIntent = new Intent(context, MainActivity.class);
//            ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            context.startActivity(ootStartIntent);
//            Log.e(TAG, "  2222222222222222  BootBroadcastReceiver onReceive(), Do thing!");
//        }
    }
}